<?php

// content="text/plain; charset=utf-8"
require_once ('../../jpgraph-3.5.0b1/src/jpgraph.php');
require_once ('../../jpgraph-3.5.0b1/src/jpgraph_line.php');
require_once '../actions/actionResult.php';
require_once '../objects/growthRace.php';

$b = $_GET['b'];
$f = $_GET['f'];
$actResult = new actionResult();
$growthDU = $actResult->growthUser($b, $f);
$growthR = $actResult->growthRace($growthDU->getNamerace());

// Some (random) data
$xdatar = array(0, 80, 160, 240, 320, 400, 480, 560, 640, 720, 800, 880, 960); //dias raza
$ydatar = array($growthR->getWeight0days(), $growthR->getWeight80days(), $growthR->getWeight160days(),
    $growthR->getWeight240days(), $growthR->getWeight320days(), $growthR->getWeight400days(), $growthR->getWeight480days(),
    $growthR->getWeight560days(), $growthR->getWeight640days(), $growthR->getWeight720days(), $growthR->getWeight800days(), $growthR->getWeight880days(),
    $growthR->getWeight960days()); //Peso por Raza
    
//Datos otorgados por el usuario//
$ydatau = array($growthDU->getWeightbirth(), $growthDU->getWeightpreweaning(), $growthDU->getWeightweaning(),
    $growthDU->getWeightpreceba(), $growthDU->getWeightceba()); //Pesos Usuario
$xdatau = array(0, $growthDU->getAgepreweaning(), $growthDU->getAgeweaning(), $growthDU->getAgepreceba(), $growthDU->getAgeceba()); //Dias Usuario

//Raza Simbrah.
$food1S = array($growthDU->getWeightbirth(), ($growthDU->getWeightpreweaning()+1.50), ($growthDU->getWeightweaning()+2.00),
    ($growthDU->getWeightpreceba()+4.01), ($growthDU->getWeightceba()+5.02)); //Pasto Maralfalfa
$food2S = array($growthDU->getWeightbirth(), ($growthDU->getWeightpreweaning()+2.50), ($growthDU->getWeightweaning()+3.34),
    ($growthDU->getWeightpreceba()+6.69), ($growthDU->getWeightceba()+8.36)); //Pasto Colosuana
//
////Raza  Brahman x Holstein
$food1BH = array($growthDU->getWeightbirth(), ($growthDU->getWeightpreweaning()+1.03), ($growthDU->getWeightweaning()+1.29),
    ($growthDU->getWeightpreceba()+2.58), ($growthDU->getWeightceba()+3.87)); //Pasto Maralfalfa
$food2BH = array($growthDU->getWeightbirth(), ($growthDU->getWeightpreweaning()+1.72), ($growthDU->getWeightweaning()+2.15),
    ($growthDU->getWeightpreceba()+4.30), ($growthDU->getWeightceba()+6.45)); //Pasto Colosuana
//
////Raza Limousin
$food1L = array($growthDU->getWeightbirth(), ($growthDU->getWeightpreweaning()+2.00), ($growthDU->getWeightweaning()+2.51),
    ($growthDU->getWeightpreceba()+4.01), ($growthDU->getWeightceba()+5.02)); //Pasto Maralfalfa
$food2L = array($growthDU->getWeightbirth(), ($growthDU->getWeightpreweaning()+3.34), ($growthDU->getWeightweaning()+4.18),
    ($growthDU->getWeightpreceba()+6.69), ($growthDU->getWeightceba()+8.36)); //Pasto Colosuana
//
////Raza Velasquez
$food1V = array($growthDU->getWeightbirth(), ($growthDU->getWeightpreweaning()+0.86), ($growthDU->getWeightweaning()+1.20),
    ($growthDU->getWeightpreceba()+2.58), ($growthDU->getWeightceba()+3.61)); //Pasto Maralfalfa
$food2V = array($growthDU->getWeightbirth(), ($growthDU->getWeightpreweaning()+1.43), ($growthDU->getWeightweaning()+2.00),
    ($growthDU->getWeightpreceba()+4.30), ($growthDU->getWeightceba()+6.02)); //Pasto Colosuana
//
////Raza Brahman
$food1B = array($growthDU->getWeightbirth(), ($growthDU->getWeightpreweaning()+1.50), ($growthDU->getWeightweaning()+2.00),
    ($growthDU->getWeightpreceba()+3.51), ($growthDU->getWeightceba()+4.82)); //Pasto Maralfalfa
$food2B = array($growthDU->getWeightbirth(), ($growthDU->getWeightpreweaning()+2.50), ($growthDU->getWeightweaning()+3.34),
    ($growthDU->getWeightpreceba()+5.85), ($growthDU->getWeightceba()+8.03)); //Pasto Colosuana
//    
////Raza Romosinuano
$food1R = array($growthDU->getWeightbirth(), ($growthDU->getWeightpreweaning()+1.03), ($growthDU->getWeightweaning()+1.29),
    ($growthDU->getWeightpreceba()+3.01), ($growthDU->getWeightceba()+3.61)); //Pasto Maralfalfa
$food2R = array($growthDU->getWeightbirth(),($growthDU->getWeightpreweaning()+1.72), ($growthDU->getWeightweaning()+2.15),
    ($growthDU->getWeightpreceba()+5.01), ($growthDU->getWeightceba()+6.02)); //Pasto Colosuana    
    
$width = 450;
$height = 350;

// Create the graph and set a scale. These two calls are always required
$graph = new Graph($width, $height);
$graph->SetScale('intlin');
$graph->SetShadow();

// Setup margin and titles
$graph->SetMargin(40, 20, 20, 40);
$graph->title->Set('Crecimiento Diario');
//$graph->subtitle->Set('(March 12, 2008)');
$graph->xaxis->title->Set('Dias');
$graph->xaxis->SetTickLabels($xdatar);
$graph->yaxis->title->Set('Peso');

$graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);

// Create the first data series
$lineplot = new LinePlot($ydatar, $xdatar);
$lineplot->SetWeight(2);   // Two pixel wide
$graph->Add($lineplot); // Add the plot to the graph
$lineplot->SetLegend('Ideal Raza ' . $growthDU->getNamerace() . '');
// Create the second data series
$lineplot2 = new LinePlot($ydatau, $xdatau);
$lineplot2->SetWeight(2);   // Two pixel wide
$graph->Add($lineplot2); // Add the second plot to the graph
$lineplot2->SetLegend('Pasto: ' . $growthDU->getFoodname() . '');

if ($growthDU->getNamerace() == 'Simbrah') {
    if ($growthDU->getFoodname() == 'Colosuna') {
        $lineplotF1S = new LinePlot($food1S, $xdatau);
        $lineplotF1S->SetWeight(2);   // Two pixel wide
        $graph->Add($lineplotF1S);
        $lineplotF1S->SetLegend('Pasto: Maralfalfa');
    } else {
        $lineplotF2S = new LinePlot($food2S, $xdatau);
        $lineplotF2S->SetWeight(2);   // Two pixel wide
        $graph->Add($lineplotF2S);
        $lineplotF2S->SetLegend('Pasto:Colosuana');
    }  
} else if ($growthDU->getNamerace() == 'Brahman x Holstein'){
    if ($growthDU->getFoodname() == 'Colosuna') {
        $lineplotF1BH = new LinePlot($food1BH, $xdatau);
        $lineplotF1BH->SetWeight(2);   // Two pixel wide
        $graph->Add($lineplotF1BH);
        $lineplotF1BH->SetLegend('Pasto: Maralfalfa');
    } else {
        $lineplotF2BH = new LinePlot($food2BH, $xdatau);
        $lineplotF2BH->SetWeight(2);   // Two pixel wide
        $graph->Add($lineplotF2BH);
        $lineplotF2BH->SetLegend('Pasto:Colosuana');
    }
} else if ($growthDU->getNamerace() == 'Limousin'){
    if ($growthDU->getFoodname() == 'Colosuna') {
        $lineplotF1L = new LinePlot($food1L, $xdatau);
        $lineplotF1L->SetWeight(2);   // Two pixel wide
        $graph->Add($lineplotF1L);
        $lineplotF1L->SetLegend('Pasto: Maralfalfa');
    } else {
        $lineplotF2L = new LinePlot($food2L, $xdatau);
        $lineplotF2L->SetWeight(2);   // Two pixel wide
        $graph->Add($lineplotF2L);
        $lineplotF2L->SetLegend('Pasto:Colosuana');
        
    }
} else if ($growthDU->getNamerace() == 'Velasquez'){
    if ($growthDU->getFoodname() == 'Colosuna') {
        $lineplotF1V = new LinePlot($food1V, $xdatau);
        $lineplotF1V->SetWeight(2);   // Two pixel wide
        $graph->Add($lineplotF1V);
        $lineplotF1V->SetLegend('Pasto: Maralfalfa');
    } else {
        $lineplotF2V = new LinePlot($food2V, $xdatau);
        $lineplotF2V->SetWeight(2);   // Two pixel wide
        $graph->Add($lineplotF2V);
        $lineplotF2V->SetLegend('Pasto:Colosuana');
    }
} else if ($growthDU->getNamerace() == 'Brahman'){
    if ($growthDU->getFoodname() == 'Colosuna') {
        $lineplotF1B = new LinePlot($food1B, $xdatau);
        $lineplotF1B->SetWeight(2);   // Two pixel wide
        $graph->Add($lineplotF1B);
        $lineplotF1B->SetLegend('Pasto:Maralfalfa');
    } else {
        $lineplotF2B = new LinePlot($food2B, $xdatau);
        $lineplotF2B->SetWeight(2);   // Two pixel wide
        $graph->Add($lineplotF2B);
    $lineplotF2B->SetLegend('Pasto:Colosuana');
    
    }
} else if($growthDU->getNamerace() == 'Romosinuano'){
    if ($growthDU->getFoodname() == 'Colosuna') {
        $lineplotF1R = new LinePlot($food1R, $xdatau);
        $lineplotF1R->SetWeight(2);   // Two pixel wide
        $graph->Add($lineplotF1R);
        $lineplotF1R->SetLegend('Pasto: Maralfalfa');
    } else {
        $lineplotF2R = new LinePlot($food2R, $xdatau);
        $lineplotF2R->SetWeight(2);   // Two pixel wide
        $graph->Add($lineplotF2R);
        $lineplotF2R->SetLegend('Pasto:Colosuana');
    }  
} 
// Adjust the legend position
$graph->legend->SetLayout(LEGEND_HOR);
$graph->legend->Pos(0.5, 0.95, "center", "bottom");
$graph->legend->SetColumns(3);

// Display the graph
$graph->Stroke();

?>
